<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>draglistgroup.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
  </script>

  <script src="static/js/doc.js">
  </script>

  <meta charset="utf8">
</head>

<body onload="prettyPrint()">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_fx_draglistgroup.js.html">draglistgroup.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line2"></a>// you may not use this file except in compliance with the License.
<a name="line3"></a>// You may obtain a copy of the License at
<a name="line4"></a>//
<a name="line5"></a>//     http://www.apache.org/licenses/LICENSE-2.0
<a name="line6"></a>//
<a name="line7"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line8"></a>// distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
<a name="line9"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line10"></a>// See the License for the specific language governing permissions and
<a name="line11"></a>// limitations under the License.
<a name="line12"></a>
<a name="line13"></a>// Copyright 2008 Google Inc. All Rights Reserved.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview A DragListGroup is a class representing a group of one or more
<a name="line17"></a> * &quot;drag lists&quot; with items that can be dragged within them and between them.
<a name="line18"></a> *
<a name="line19"></a> * @see ../demos/draglistgroup.html
<a name="line20"></a> */
<a name="line21"></a>
<a name="line22"></a>
<a name="line23"></a>goog.provide(&#39;goog.fx.DragListDirection&#39;);
<a name="line24"></a>goog.provide(&#39;goog.fx.DragListGroup&#39;);
<a name="line25"></a>goog.provide(&#39;goog.fx.DragListGroupEvent&#39;);
<a name="line26"></a>
<a name="line27"></a>goog.require(&#39;goog.dom&#39;);
<a name="line28"></a>goog.require(&#39;goog.dom.NodeType&#39;);
<a name="line29"></a>goog.require(&#39;goog.dom.classes&#39;);
<a name="line30"></a>goog.require(&#39;goog.events.EventHandler&#39;);
<a name="line31"></a>goog.require(&#39;goog.events.EventTarget&#39;);
<a name="line32"></a>goog.require(&#39;goog.events.EventType&#39;);
<a name="line33"></a>goog.require(&#39;goog.fx.Dragger&#39;);
<a name="line34"></a>goog.require(&#39;goog.fx.Dragger.EventType&#39;);
<a name="line35"></a>goog.require(&#39;goog.math.Coordinate&#39;);
<a name="line36"></a>goog.require(&#39;goog.style&#39;);
<a name="line37"></a>
<a name="line38"></a>
<a name="line39"></a>/**
<a name="line40"></a> * A class representing a group of one or more &quot;drag lists&quot; with items that can
<a name="line41"></a> * be dragged within them and between them.
<a name="line42"></a> *
<a name="line43"></a> * Example usage:
<a name="line44"></a> *   var dragListGroup = new goog.fx.DragListGroup();
<a name="line45"></a> *   dragListGroup.setDragItemHandleHoverClass(className1);
<a name="line46"></a> *   dragListGroup.setDraggerElClass(className2);
<a name="line47"></a> *   dragListGroup.addDragList(vertList, goog.fx.DragListDirection.DOWN);
<a name="line48"></a> *   dragListGroup.addDragList(horizList, goog.fx.DragListDirection.RIGHT);
<a name="line49"></a> *   dragListGroup.init();
<a name="line50"></a> *
<a name="line51"></a> * @extends {goog.events.EventTarget}
<a name="line52"></a> * @constructor
<a name="line53"></a> */
<a name="line54"></a>goog.fx.DragListGroup = function() {
<a name="line55"></a>  goog.events.EventTarget.call(this);
<a name="line56"></a>
<a name="line57"></a>  /**
<a name="line58"></a>   * The drag lists.
<a name="line59"></a>   * @type {Array.&lt;Element&gt;}
<a name="line60"></a>   * @private
<a name="line61"></a>   */
<a name="line62"></a>  this.dragLists_ = [];
<a name="line63"></a>
<a name="line64"></a>  /**
<a name="line65"></a>   * All the drag items. Set by init().
<a name="line66"></a>   * @type {Array.&lt;Element&gt;}
<a name="line67"></a>   * @private
<a name="line68"></a>   */
<a name="line69"></a>  this.dragItems_ = [];
<a name="line70"></a>
<a name="line71"></a>  /**
<a name="line72"></a>   * Which drag item corresponds to a given handle.  Set by init().
<a name="line73"></a>   * Specifically, this maps from the hash code (as given by goog.getHashCode)
<a name="line74"></a>   * of the handle to the drag item.
<a name="line75"></a>   * @type {Object}
<a name="line76"></a>   * @private
<a name="line77"></a>   */
<a name="line78"></a>  this.dragItemForHandle_ = {};
<a name="line79"></a>
<a name="line80"></a>  /**
<a name="line81"></a>   * The event handler for this instance.
<a name="line82"></a>   * @type {goog.events.EventHandler}
<a name="line83"></a>   * @private
<a name="line84"></a>   */
<a name="line85"></a>  this.eventHandler_ = new goog.events.EventHandler(this);
<a name="line86"></a>
<a name="line87"></a>  /**
<a name="line88"></a>   * Whether the setup has been done to make all items in all lists draggable.
<a name="line89"></a>   * @type {boolean}
<a name="line90"></a>   * @private
<a name="line91"></a>   */
<a name="line92"></a>  this.isInitialized_ = false;
<a name="line93"></a>
<a name="line94"></a>};
<a name="line95"></a>goog.inherits(goog.fx.DragListGroup, goog.events.EventTarget);
<a name="line96"></a>
<a name="line97"></a>
<a name="line98"></a>
<a name="line99"></a>/**
<a name="line100"></a> * Enum to indicate the direction that a drag list grows.
<a name="line101"></a> * @enum {number}
<a name="line102"></a> */
<a name="line103"></a>goog.fx.DragListDirection = {
<a name="line104"></a>  DOWN: 0,  // common
<a name="line105"></a>  UP: 1,  // very rare
<a name="line106"></a>  RIGHT: 2,  // common
<a name="line107"></a>  LEFT: 3  // uncommon (except perhaps for right-to-left interfaces)
<a name="line108"></a>};
<a name="line109"></a>
<a name="line110"></a>
<a name="line111"></a>/**
<a name="line112"></a> * Events dispatched by this class.
<a name="line113"></a> * @type {Object}
<a name="line114"></a> */
<a name="line115"></a>goog.fx.DragListGroup.EventType = {
<a name="line116"></a>  BEFOREDRAGSTART: &#39;beforedragstart&#39;,
<a name="line117"></a>  DRAGSTART: &#39;dragstart&#39;,
<a name="line118"></a>  BEFOREDRAGMOVE: &#39;beforedragmove&#39;,
<a name="line119"></a>  DRAGMOVE: &#39;dragmove&#39;,
<a name="line120"></a>  BEFOREDRAGEND: &#39;beforedragend&#39;,
<a name="line121"></a>  DRAGEND: &#39;dragend&#39;
<a name="line122"></a>};
<a name="line123"></a>
<a name="line124"></a>
<a name="line125"></a>// The next 4 are user-supplied CSS classes.
<a name="line126"></a>
<a name="line127"></a>/**
<a name="line128"></a> * The user-supplied CSS class to add to a drag item on hover (not during a
<a name="line129"></a> * drag action).
<a name="line130"></a> * @type {string|undefined}
<a name="line131"></a> * @private
<a name="line132"></a> */
<a name="line133"></a>goog.fx.DragListGroup.prototype.dragItemHoverClass_;
<a name="line134"></a>
<a name="line135"></a>
<a name="line136"></a>/**
<a name="line137"></a> * The user-supplied CSS class to add to a drag item handle on hover (not
<a name="line138"></a> * during a drag action).
<a name="line139"></a> * @type {string|undefined}
<a name="line140"></a> * @private
<a name="line141"></a> */
<a name="line142"></a>goog.fx.DragListGroup.prototype.dragItemHandleHoverClass_;
<a name="line143"></a>
<a name="line144"></a>
<a name="line145"></a>/**
<a name="line146"></a> * The user-supplied CSS class to add to the current drag item (during a
<a name="line147"></a> * drag action).
<a name="line148"></a> * @type {string|undefined}
<a name="line149"></a> * @private
<a name="line150"></a> */
<a name="line151"></a>goog.fx.DragListGroup.prototype.currDragItemClass_;
<a name="line152"></a>
<a name="line153"></a>
<a name="line154"></a>/**
<a name="line155"></a> * The user-supplied CSS class to add to the clone of the current drag item
<a name="line156"></a> * that&#39;s actually being dragged around (during a drag action).
<a name="line157"></a> * @type {string|undefined}
<a name="line158"></a> * @private
<a name="line159"></a> */
<a name="line160"></a>goog.fx.DragListGroup.prototype.draggerElClass_;
<a name="line161"></a>
<a name="line162"></a>
<a name="line163"></a>// The next 5 are info applicable during a drag action.
<a name="line164"></a>
<a name="line165"></a>/**
<a name="line166"></a> * The current drag item being moved.
<a name="line167"></a> * Note: This is only defined while a drag action is happening.
<a name="line168"></a> * @type {Element}
<a name="line169"></a> * @private
<a name="line170"></a> */
<a name="line171"></a>goog.fx.DragListGroup.prototype.currDragItem_;
<a name="line172"></a>
<a name="line173"></a>
<a name="line174"></a>/**
<a name="line175"></a> * The original drag list that the current drag item came from. We need to
<a name="line176"></a> * remember this in case the user drops the item outside of any lists, in which
<a name="line177"></a> * case we return the item to its original location.
<a name="line178"></a> * Note: This is only defined while a drag action is happening.
<a name="line179"></a> * @type {Element}
<a name="line180"></a> * @private
<a name="line181"></a> */
<a name="line182"></a>goog.fx.DragListGroup.prototype.origList_;
<a name="line183"></a>
<a name="line184"></a>
<a name="line185"></a>/**
<a name="line186"></a> * The original next item in the original list that the current drag item came
<a name="line187"></a> * from. We need to remember this in case the user drops the item outside of
<a name="line188"></a> * any lists, in which case we return the item to its original location.
<a name="line189"></a> * Note: This is only defined while a drag action is happening.
<a name="line190"></a> * @type {Element}
<a name="line191"></a> * @private
<a name="line192"></a> */
<a name="line193"></a>goog.fx.DragListGroup.prototype.origNextItem_;
<a name="line194"></a>
<a name="line195"></a>
<a name="line196"></a>/**
<a name="line197"></a> * The clone of the current drag item that&#39;s actually being dragged around.
<a name="line198"></a> * Note: This is only defined while a drag action is happening.
<a name="line199"></a> * @type {Element}
<a name="line200"></a> * @private
<a name="line201"></a> */
<a name="line202"></a>goog.fx.DragListGroup.prototype.draggerEl_;
<a name="line203"></a>
<a name="line204"></a>
<a name="line205"></a>/**
<a name="line206"></a> * The dragger object.
<a name="line207"></a> * Note: This is only defined while a drag action is happening.
<a name="line208"></a> * @type {goog.fx.Dragger}
<a name="line209"></a> * @private
<a name="line210"></a> */
<a name="line211"></a>goog.fx.DragListGroup.prototype.dragger_;
<a name="line212"></a>
<a name="line213"></a>
<a name="line214"></a>
<a name="line215"></a>/**
<a name="line216"></a> * Adds a drag list to this DragListGroup.
<a name="line217"></a> * All calls to this method must happen before the call to init().
<a name="line218"></a> * Remember that all child nodes (except text nodes) will be made draggable to
<a name="line219"></a> * any other drag list in this group.
<a name="line220"></a> *
<a name="line221"></a> * @param {Element} dragListElement Must be a container for a list of items
<a name="line222"></a> *     that should all be made draggable.
<a name="line223"></a> * @param {goog.fx.DragListDirection} growthDirection The direction that this
<a name="line224"></a> *     drag list grows in (i.e.. if an item is added, the list&#39;s bounding box
<a name="line225"></a> *     expands in this direction).
<a name="line226"></a> * @param {boolean} opt_isDocOrderSameAsGrowthDirection Defaults to true.
<a name="line227"></a> *     Whether or not the ordering of this drag list&#39;s items in the document
<a name="line228"></a> *     is the same as the list&#39;s growth direction.
<a name="line229"></a> * @param {string} opt_dragHoverClass CSS class to apply to this drag list when
<a name="line230"></a> *     the draggerEl hovers over it during a drag action.
<a name="line231"></a> */
<a name="line232"></a>goog.fx.DragListGroup.prototype.addDragList = function(
<a name="line233"></a>    dragListElement, growthDirection, opt_isDocOrderSameAsGrowthDirection,
<a name="line234"></a>    opt_dragHoverClass) {
<a name="line235"></a>  this.assertNotInitialized_();
<a name="line236"></a>
<a name="line237"></a>  dragListElement.dlgGrowthDirection_ = growthDirection;
<a name="line238"></a>  dragListElement.dlgIsDocOrderSameAsGrowthDirection_ =
<a name="line239"></a>      opt_isDocOrderSameAsGrowthDirection !== false;
<a name="line240"></a>  dragListElement.dlgDragHoverClass_ = opt_dragHoverClass;
<a name="line241"></a>  this.dragLists_.push(dragListElement);
<a name="line242"></a>};
<a name="line243"></a>
<a name="line244"></a>
<a name="line245"></a>/**
<a name="line246"></a> * Sets a user-supplied function used to get the &quot;handle&quot; element for a drag
<a name="line247"></a> * item. The function must accept exactly one argument. The argument may be
<a name="line248"></a> * any drag item element.
<a name="line249"></a> *
<a name="line250"></a> * If not set, the default implementation uses the whole drag item as the
<a name="line251"></a> * handle.
<a name="line252"></a> *
<a name="line253"></a> * @param {function(Element): Element} getHandleForDragItemFn A function that,
<a name="line254"></a> *     given any drag item, returns a reference to its &quot;handle&quot; element
<a name="line255"></a> *     (which may be the drag item element itself).
<a name="line256"></a> */
<a name="line257"></a>goog.fx.DragListGroup.prototype.setFunctionToGetHandleForDragItem = function(
<a name="line258"></a>    getHandleForDragItemFn) {
<a name="line259"></a>  this.assertNotInitialized_();
<a name="line260"></a>  this.getHandleForDragItem_ = getHandleForDragItemFn;
<a name="line261"></a>};
<a name="line262"></a>
<a name="line263"></a>
<a name="line264"></a>/**
<a name="line265"></a> * Sets a user-supplied CSS class to add to a drag item on hover (not during a
<a name="line266"></a> * drag action).
<a name="line267"></a> * @param {string} dragItemHoverClass The CSS class.
<a name="line268"></a> */
<a name="line269"></a>goog.fx.DragListGroup.prototype.setDragItemHoverClass = function(
<a name="line270"></a>    dragItemHoverClass) {
<a name="line271"></a>  this.assertNotInitialized_();
<a name="line272"></a>  this.dragItemHoverClass_ = dragItemHoverClass;
<a name="line273"></a>};
<a name="line274"></a>
<a name="line275"></a>
<a name="line276"></a>/**
<a name="line277"></a> * Sets a user-supplied CSS class to add to a drag item handle on hover (not
<a name="line278"></a> * during a drag action).
<a name="line279"></a> * @param {string} dragItemHandleHoverClass The CSS class.
<a name="line280"></a> */
<a name="line281"></a>goog.fx.DragListGroup.prototype.setDragItemHandleHoverClass = function(
<a name="line282"></a>    dragItemHandleHoverClass) {
<a name="line283"></a>  this.assertNotInitialized_();
<a name="line284"></a>  this.dragItemHandleHoverClass_ = dragItemHandleHoverClass;
<a name="line285"></a>};
<a name="line286"></a>
<a name="line287"></a>
<a name="line288"></a>/**
<a name="line289"></a> * Sets a user-supplied CSS class to add to the current drag item (during a
<a name="line290"></a> * drag action).
<a name="line291"></a> *
<a name="line292"></a> * If not set, the default behavior adds visibility:hidden to the current drag
<a name="line293"></a> * item so that it is a block of empty space in the hover drag list (if any).
<a name="line294"></a> * If this class is set by the user, then the default behavior does not happen
<a name="line295"></a> * (unless, of course, the class also contains visibility:hidden).
<a name="line296"></a> *
<a name="line297"></a> * @param {string} currDragItemClass The CSS class.
<a name="line298"></a> */
<a name="line299"></a>goog.fx.DragListGroup.prototype.setCurrDragItemClass = function(
<a name="line300"></a>    currDragItemClass) {
<a name="line301"></a>  this.assertNotInitialized_();
<a name="line302"></a>  this.currDragItemClass_ = currDragItemClass;
<a name="line303"></a>};
<a name="line304"></a>
<a name="line305"></a>
<a name="line306"></a>/**
<a name="line307"></a> * Sets a user-supplied CSS class to add to the clone of the current drag item
<a name="line308"></a> * that&#39;s actually being dragged around (during a drag action).
<a name="line309"></a> * @param {string} draggerElClass The CSS class.
<a name="line310"></a> */
<a name="line311"></a>goog.fx.DragListGroup.prototype.setDraggerElClass = function(draggerElClass) {
<a name="line312"></a>  this.assertNotInitialized_();
<a name="line313"></a>  this.draggerElClass_ = draggerElClass;
<a name="line314"></a>};
<a name="line315"></a>
<a name="line316"></a>
<a name="line317"></a>/**
<a name="line318"></a> * Performs the initial setup to make all items in all lists draggable.
<a name="line319"></a> */
<a name="line320"></a>goog.fx.DragListGroup.prototype.init = function() {
<a name="line321"></a>  if (this.isInitialized_) {
<a name="line322"></a>    return;
<a name="line323"></a>  }
<a name="line324"></a>
<a name="line325"></a>  for (var i = 0, numLists = this.dragLists_.length; i &lt; numLists; i++) {
<a name="line326"></a>    var dragList = this.dragLists_[i];
<a name="line327"></a>
<a name="line328"></a>    var dragItems = this.getItemsInDragList_(dragList);
<a name="line329"></a>    for (var j = 0, numItems = dragItems.length; j &lt; numItems; ++j) {
<a name="line330"></a>      var dragItem = dragItems[j];
<a name="line331"></a>      var dragItemHandle = this.getHandleForDragItem_(dragItem);
<a name="line332"></a>
<a name="line333"></a>      var hc = goog.getHashCode(dragItemHandle);
<a name="line334"></a>      this.dragItemForHandle_[hc] = dragItem;
<a name="line335"></a>
<a name="line336"></a>      if (this.dragItemHoverClass_) {
<a name="line337"></a>        this.eventHandler_.listen(
<a name="line338"></a>            dragItem, goog.events.EventType.MOUSEOVER,
<a name="line339"></a>            this.handleDragItemMouseover_);
<a name="line340"></a>        this.eventHandler_.listen(
<a name="line341"></a>            dragItem, goog.events.EventType.MOUSEOUT,
<a name="line342"></a>            this.handleDragItemMouseout_);
<a name="line343"></a>      }
<a name="line344"></a>      if (this.dragItemHandleHoverClass_) {
<a name="line345"></a>        this.eventHandler_.listen(
<a name="line346"></a>            dragItemHandle, goog.events.EventType.MOUSEOVER,
<a name="line347"></a>            this.handleDragItemHandleMouseover_);
<a name="line348"></a>        this.eventHandler_.listen(
<a name="line349"></a>            dragItemHandle, goog.events.EventType.MOUSEOUT,
<a name="line350"></a>            this.handleDragItemHandleMouseout_);
<a name="line351"></a>      }
<a name="line352"></a>
<a name="line353"></a>      this.dragItems_.push(dragItem);
<a name="line354"></a>      this.eventHandler_.listen(
<a name="line355"></a>          dragItemHandle, goog.events.EventType.MOUSEDOWN,
<a name="line356"></a>          this.handleDragStart_);
<a name="line357"></a>    }
<a name="line358"></a>  }
<a name="line359"></a>
<a name="line360"></a>  this.isInitialized_ = true;
<a name="line361"></a>};
<a name="line362"></a>
<a name="line363"></a>
<a name="line364"></a>/**
<a name="line365"></a> * Disposes of the DragListGroup.
<a name="line366"></a> */
<a name="line367"></a>goog.fx.DragListGroup.prototype.disposeInternal = function() {
<a name="line368"></a>  this.eventHandler_.dispose();
<a name="line369"></a>
<a name="line370"></a>  for (var i = 0, n = this.dragLists_.length; i &lt; n; i++) {
<a name="line371"></a>    var dragList = this.dragLists_[i];
<a name="line372"></a>    // Note: IE doesn&#39;t allow &#39;delete&#39; for fields on HTML elements (because
<a name="line373"></a>    // they&#39;re not real JS objects in IE), so we just set them to undefined.
<a name="line374"></a>    dragList.dlgGrowthDirection_ = undefined;
<a name="line375"></a>    dragList.dlgIsDocOrderSameAsGrowthDirection_ = undefined;
<a name="line376"></a>    dragList.dlgDragHoverClass_ = undefined;
<a name="line377"></a>  }
<a name="line378"></a>
<a name="line379"></a>  this.dragLists_.length = 0;
<a name="line380"></a>  this.dragItems_.length = 0;
<a name="line381"></a>  this.dragItemForHandle_ = null;
<a name="line382"></a>
<a name="line383"></a>  goog.fx.DragListGroup.superClass_.disposeInternal.call(this);
<a name="line384"></a>};
<a name="line385"></a>
<a name="line386"></a>
<a name="line387"></a>
<a name="line388"></a>/**
<a name="line389"></a> * Handles the start of a drag action (i.e. MOUSEDOWN on any drag item).
<a name="line390"></a> *
<a name="line391"></a> * @param {goog.events.BrowserEvent} e Event object fired on a drag item handle.
<a name="line392"></a> * @return {boolean} Whether the event was handled.
<a name="line393"></a> * @private
<a name="line394"></a> */
<a name="line395"></a>goog.fx.DragListGroup.prototype.handleDragStart_ = function(e) {
<a name="line396"></a>
<a name="line397"></a>  var hc = goog.getHashCode(/** @type {Node} */ (e.currentTarget));
<a name="line398"></a>  var currDragItem = /** @type {Element} */ (this.dragItemForHandle_[hc]);
<a name="line399"></a>
<a name="line400"></a>  var rv = this.dispatchEvent(
<a name="line401"></a>      new goog.fx.DragListGroupEvent(
<a name="line402"></a>          goog.fx.DragListGroup.EventType.BEFOREDRAGSTART, this, e,
<a name="line403"></a>          currDragItem, null, null));
<a name="line404"></a>  if (!rv) {
<a name="line405"></a>    return false;
<a name="line406"></a>  }
<a name="line407"></a>
<a name="line408"></a>  this.currDragItem_ = currDragItem;
<a name="line409"></a>
<a name="line410"></a>  // Record the original location of the current drag item.
<a name="line411"></a>  // Note: this.origNextItem_ may be null.
<a name="line412"></a>  this.origList_ = /** @type {Element} */ (currDragItem.parentNode);
<a name="line413"></a>  this.origNextItem_ = goog.dom.getNextElementSibling(currDragItem);
<a name="line414"></a>
<a name="line415"></a>  // Create a clone for dragging.
<a name="line416"></a>  var draggerEl = this.cloneNode_(currDragItem);
<a name="line417"></a>  this.draggerEl_ = draggerEl;
<a name="line418"></a>
<a name="line419"></a>  // If there&#39;s a CSS class specified for the current drag item, add it.
<a name="line420"></a>  // Otherwise, make the actual current drag item hidden (takes up space).
<a name="line421"></a>  if (this.currDragItemClass_) {
<a name="line422"></a>    goog.dom.classes.add(currDragItem, this.currDragItemClass_);
<a name="line423"></a>  } else {
<a name="line424"></a>    currDragItem.style.visibility = &#39;hidden&#39;;
<a name="line425"></a>  }
<a name="line426"></a>
<a name="line427"></a>  // Add CSS class for the clone, if any.
<a name="line428"></a>  if (this.draggerElClass_) {
<a name="line429"></a>    goog.dom.classes.add(draggerEl, this.draggerElClass_);
<a name="line430"></a>  }
<a name="line431"></a>
<a name="line432"></a>  // Place the clone (i.e. draggerEl) at the same position as the actual
<a name="line433"></a>  // current drag item. This is a bit tricky since
<a name="line434"></a>  //   goog.style.getPageOffset() gets the left-top pos of the border, but
<a name="line435"></a>  //   goog.style.setPageOffset() sets the left-top pos of the margin.
<a name="line436"></a>  // It&#39;s difficult to adjust for the margins of the clone because it&#39;s
<a name="line437"></a>  // difficult to read it: goog.style.getComputedStyle() doesn&#39;t work for IE.
<a name="line438"></a>  // Instead, our workaround is simply to set the clone&#39;s margins to 0px.
<a name="line439"></a>  draggerEl.style.margin = &#39;0px&#39;;
<a name="line440"></a>  draggerEl.style.position = &#39;absolute&#39;;
<a name="line441"></a>  goog.dom.getOwnerDocument(currDragItem).body.appendChild(draggerEl);
<a name="line442"></a>  // Important: goog.style.setPageOffset() only works correctly for IE when the
<a name="line443"></a>  // element is already in the document.
<a name="line444"></a>  var currDragItemPos = goog.style.getPageOffset(currDragItem);
<a name="line445"></a>  goog.style.setPageOffset(draggerEl, currDragItemPos);
<a name="line446"></a>
<a name="line447"></a>  // Precompute distances from top-left corner to center for efficiency.
<a name="line448"></a>  var draggerElSize = goog.style.getSize(draggerEl);
<a name="line449"></a>  draggerEl.halfWidth = draggerElSize.width / 2;
<a name="line450"></a>  draggerEl.halfHeight = draggerElSize.height / 2;
<a name="line451"></a>
<a name="line452"></a>  // Record the bounds of all the drag lists and all the other drag items, in
<a name="line453"></a>  // the state where the current drag item is not in any of the lists. (This
<a name="line454"></a>  // caching is for efficiency, so that we don&#39;t have to recompute the bounds
<a name="line455"></a>  // on each drag move.)
<a name="line456"></a>  currDragItem.style.display = &#39;none&#39;;
<a name="line457"></a>  for (var i = 0, n = this.dragLists_.length; i &lt; n; i++) {
<a name="line458"></a>    var dragList = this.dragLists_[i];
<a name="line459"></a>    dragList.dlgBounds_ = goog.style.getBounds(dragList);
<a name="line460"></a>  }
<a name="line461"></a>  for (var i = 0, n = this.dragItems_.length; i &lt; n; i++) {
<a name="line462"></a>    var dragItem = this.dragItems_[i];
<a name="line463"></a>    if (dragItem != currDragItem) {
<a name="line464"></a>      dragItem.dlgBounds_ = goog.style.getBounds(dragItem);
<a name="line465"></a>    }
<a name="line466"></a>  }
<a name="line467"></a>  currDragItem.style.display = &#39;&#39;;
<a name="line468"></a>
<a name="line469"></a>  // Create the dragger object.
<a name="line470"></a>  this.dragger_ = new goog.fx.Dragger(draggerEl);
<a name="line471"></a>
<a name="line472"></a>  // Listen to events on the dragger.
<a name="line473"></a>  this.eventHandler_.listen(
<a name="line474"></a>      this.dragger_, goog.fx.Dragger.EventType.DRAG, this.handleDragMove_);
<a name="line475"></a>  this.eventHandler_.listen(
<a name="line476"></a>      this.dragger_, goog.fx.Dragger.EventType.END, this.handleDragEnd_);
<a name="line477"></a>
<a name="line478"></a>  // Manually start up the dragger.
<a name="line479"></a>  this.dragger_.startDrag(e);
<a name="line480"></a>
<a name="line481"></a>  this.dispatchEvent(
<a name="line482"></a>      new goog.fx.DragListGroupEvent(
<a name="line483"></a>          goog.fx.DragListGroup.EventType.DRAGSTART, this, e,
<a name="line484"></a>          currDragItem, draggerEl, this.dragger_));
<a name="line485"></a>
<a name="line486"></a>  return true;
<a name="line487"></a>};
<a name="line488"></a>
<a name="line489"></a>
<a name="line490"></a>/**
<a name="line491"></a> * Handles a drag movement (i.e. DRAG event fired by the dragger).
<a name="line492"></a> *
<a name="line493"></a> * @param {goog.fx.DragEvent} dragEvent Event object fired by the dragger.
<a name="line494"></a> * @return {boolean} The return value for the event.
<a name="line495"></a> * @private
<a name="line496"></a> */
<a name="line497"></a>goog.fx.DragListGroup.prototype.handleDragMove_ = function(dragEvent) {
<a name="line498"></a>
<a name="line499"></a>  // Compute the center of the dragger element (i.e. the cloned drag item).
<a name="line500"></a>  var draggerElPos = goog.style.getPageOffset(this.draggerEl_);
<a name="line501"></a>  var draggerElCenter = new goog.math.Coordinate(
<a name="line502"></a>      draggerElPos.x + this.draggerEl_.halfWidth,
<a name="line503"></a>      draggerElPos.y + this.draggerEl_.halfHeight);
<a name="line504"></a>
<a name="line505"></a>  // Check whether the center is hovering over one of the drag lists.
<a name="line506"></a>  var hoverList = this.getHoverDragList_(draggerElCenter);
<a name="line507"></a>
<a name="line508"></a>  // If hovering over a list, find the next item (if drag were to end now).
<a name="line509"></a>  var hoverNextItem =
<a name="line510"></a>      hoverList ? this.getHoverNextItem_(hoverList, draggerElCenter) : null;
<a name="line511"></a>
<a name="line512"></a>  var rv = this.dispatchEvent(
<a name="line513"></a>      new goog.fx.DragListGroupEvent(
<a name="line514"></a>          goog.fx.DragListGroup.EventType.BEFOREDRAGMOVE, this, dragEvent,
<a name="line515"></a>          this.currDragItem_, this.draggerEl_, this.dragger_,
<a name="line516"></a>          draggerElCenter, hoverList, hoverNextItem));
<a name="line517"></a>  if (!rv) {
<a name="line518"></a>    return false;
<a name="line519"></a>  }
<a name="line520"></a>
<a name="line521"></a>  if (hoverList) {
<a name="line522"></a>    this.insertCurrDragItem_(hoverList, hoverNextItem);
<a name="line523"></a>    this.currDragItem_.style.display = &#39;&#39;;
<a name="line524"></a>    // Add drag list&#39;s hover class (if any).
<a name="line525"></a>    if (hoverList.dlgDragHoverClass_) {
<a name="line526"></a>      goog.dom.classes.add(hoverList, hoverList.dlgDragHoverClass_);
<a name="line527"></a>    }
<a name="line528"></a>
<a name="line529"></a>  } else {
<a name="line530"></a>    // Not hovering over a drag list, so remove the item altogether.
<a name="line531"></a>    this.currDragItem_.style.display = &#39;none&#39;;
<a name="line532"></a>    // Remove hover classes (if any) from all drag lists.
<a name="line533"></a>    for (var i = 0, n = this.dragLists_.length; i &lt; n; i++) {
<a name="line534"></a>      var dragList = this.dragLists_[i];
<a name="line535"></a>      if (dragList.dlgDragHoverClass_) {
<a name="line536"></a>        goog.dom.classes.remove(dragList, dragList.dlgDragHoverClass_);
<a name="line537"></a>      }
<a name="line538"></a>    }
<a name="line539"></a>  }
<a name="line540"></a>
<a name="line541"></a>  this.dispatchEvent(
<a name="line542"></a>      new goog.fx.DragListGroupEvent(
<a name="line543"></a>          goog.fx.DragListGroup.EventType.DRAGMOVE, this, dragEvent,
<a name="line544"></a>          /** @type {Element} */ (this.currDragItem_),
<a name="line545"></a>          this.draggerEl_, this.dragger_,
<a name="line546"></a>          draggerElCenter, hoverList, hoverNextItem));
<a name="line547"></a>
<a name="line548"></a>  // Return false to prevent selection due to mouse drag.
<a name="line549"></a>  return false;
<a name="line550"></a>};
<a name="line551"></a>
<a name="line552"></a>
<a name="line553"></a>/**
<a name="line554"></a> * Handles the end of a drag action (i.e. END event fired by the dragger).
<a name="line555"></a> *
<a name="line556"></a> * @param {goog.fx.DragEvent} dragEvent Event object fired by the dragger.
<a name="line557"></a> * @return {boolean} Whether the event was handled.
<a name="line558"></a> * @private
<a name="line559"></a> */
<a name="line560"></a>goog.fx.DragListGroup.prototype.handleDragEnd_ = function(dragEvent) {
<a name="line561"></a>
<a name="line562"></a>  var rv = this.dispatchEvent(
<a name="line563"></a>      new goog.fx.DragListGroupEvent(
<a name="line564"></a>          goog.fx.DragListGroup.EventType.BEFOREDRAGEND, this, dragEvent,
<a name="line565"></a>          /** @type {Element} */ (this.currDragItem_),
<a name="line566"></a>          this.draggerEl_, this.dragger_));
<a name="line567"></a>  if (!rv) {
<a name="line568"></a>    return false;
<a name="line569"></a>  }
<a name="line570"></a>
<a name="line571"></a>  // Disposes of the dragger and remove the cloned drag item.
<a name="line572"></a>  this.dragger_.dispose();
<a name="line573"></a>  goog.dom.removeNode(this.draggerEl_);
<a name="line574"></a>
<a name="line575"></a>  // If the current drag item is not in any list, put it back in its original
<a name="line576"></a>  // location.
<a name="line577"></a>  if (this.currDragItem_.style.display == &#39;none&#39;) {
<a name="line578"></a>    // Note: this.origNextItem_ may be null, but insertBefore() still works.
<a name="line579"></a>    this.origList_.insertBefore(this.currDragItem_, this.origNextItem_);
<a name="line580"></a>    this.currDragItem_.style.display = &#39;&#39;;
<a name="line581"></a>  }
<a name="line582"></a>
<a name="line583"></a>  // If there&#39;s a CSS class specified for the current drag item, remove it.
<a name="line584"></a>  // Otherwise, make the current drag item visible (instead of empty space).
<a name="line585"></a>  if (this.currDragItemClass_) {
<a name="line586"></a>    goog.dom.classes.remove(this.currDragItem_, this.currDragItemClass_);
<a name="line587"></a>  } else {
<a name="line588"></a>    this.currDragItem_.style.visibility = &#39;visible&#39;;
<a name="line589"></a>  }
<a name="line590"></a>
<a name="line591"></a>  // Remove hover classes (if any) from all drag lists.
<a name="line592"></a>  for (var i = 0, n = this.dragLists_.length; i &lt; n; i++) {
<a name="line593"></a>    var dragList = this.dragLists_[i];
<a name="line594"></a>    if (dragList.dlgDragHoverClass_) {
<a name="line595"></a>      goog.dom.classes.remove(dragList, dragList.dlgDragHoverClass_);
<a name="line596"></a>    }
<a name="line597"></a>  }
<a name="line598"></a>
<a name="line599"></a>  this.dispatchEvent(
<a name="line600"></a>      new goog.fx.DragListGroupEvent(
<a name="line601"></a>          goog.fx.DragListGroup.EventType.DRAGEND, this, dragEvent,
<a name="line602"></a>          this.currDragItem_, this.draggerEl_, this.dragger_));
<a name="line603"></a>
<a name="line604"></a>  // Clear all our temporary fields that are only defined while dragging.
<a name="line605"></a>  this.currDragItem_ = null;
<a name="line606"></a>  this.origList_ = null;
<a name="line607"></a>  this.origNextItem_ = null;
<a name="line608"></a>  this.draggerEl_ = null;
<a name="line609"></a>  this.dragger_ = null;
<a name="line610"></a>
<a name="line611"></a>  // Clear all the bounds info stored on the drag lists and drag elements.
<a name="line612"></a>  // Note: IE doesn&#39;t allow &#39;delete&#39; for fields on HTML elements (because
<a name="line613"></a>  // they&#39;re not real JS objects in IE), so we just set them to undefined.
<a name="line614"></a>  for (var i = 0, n = this.dragLists_.length; i &lt; n; i++) {
<a name="line615"></a>    this.dragLists_[i].dlgBounds_ = null;
<a name="line616"></a>  }
<a name="line617"></a>  for (var i = 0, n = this.dragItems_.length; i &lt; n; i++) {
<a name="line618"></a>    this.dragItems_[i].dlgBounds_ = null;
<a name="line619"></a>  }
<a name="line620"></a>
<a name="line621"></a>  return true;
<a name="line622"></a>};
<a name="line623"></a>
<a name="line624"></a>
<a name="line625"></a>
<a name="line626"></a>/**
<a name="line627"></a> * Asserts that this DragListGroup instance is not yet initialized.
<a name="line628"></a> * @throws {Error} If this DragListGroup is already initialized.
<a name="line629"></a> * @private
<a name="line630"></a> */
<a name="line631"></a>goog.fx.DragListGroup.prototype.assertNotInitialized_ = function() {
<a name="line632"></a>  if (this.isInitialized_) {
<a name="line633"></a>    throw Error(&#39;This action is not allowed after calling init().&#39;);
<a name="line634"></a>  }
<a name="line635"></a>};
<a name="line636"></a>
<a name="line637"></a>
<a name="line638"></a>/**
<a name="line639"></a> * Default implementation of the function to get the &quot;handle&quot; element for a
<a name="line640"></a> * drag item. By default, we use the whole drag item as the handle. Users can
<a name="line641"></a> * change this by calling setFunctionToGetHandleForDragItem().
<a name="line642"></a> *
<a name="line643"></a> * @param {Element} dragItem The drag item to get the handle for.
<a name="line644"></a> * @return {Element} The dragItem element itself.
<a name="line645"></a> * @private
<a name="line646"></a> */
<a name="line647"></a>goog.fx.DragListGroup.prototype.getHandleForDragItem_ = function(dragItem) {
<a name="line648"></a>  return dragItem;
<a name="line649"></a>};
<a name="line650"></a>
<a name="line651"></a>
<a name="line652"></a>/**
<a name="line653"></a> * Handles a MOUSEOVER event fired on a drag item.
<a name="line654"></a> * @param {goog.events.BrowserEvent} e The event.
<a name="line655"></a> * @private
<a name="line656"></a> */
<a name="line657"></a>goog.fx.DragListGroup.prototype.handleDragItemMouseover_ = function(e) {
<a name="line658"></a>  goog.dom.classes.add(/** @type {Element} */ (e.currentTarget),
<a name="line659"></a>      this.dragItemHoverClass_);
<a name="line660"></a>};
<a name="line661"></a>
<a name="line662"></a>
<a name="line663"></a>/**
<a name="line664"></a> * Handles a MOUSEOUT event fired on a drag item.
<a name="line665"></a> * @param {goog.events.BrowserEvent} e The event.
<a name="line666"></a> * @private
<a name="line667"></a> */
<a name="line668"></a>goog.fx.DragListGroup.prototype.handleDragItemMouseout_ = function(e) {
<a name="line669"></a>  goog.dom.classes.remove(/** @type {Element} */ (e.currentTarget),
<a name="line670"></a>      this.dragItemHoverClass_);
<a name="line671"></a>};
<a name="line672"></a>
<a name="line673"></a>
<a name="line674"></a>/**
<a name="line675"></a> * Handles a MOUSEOVER event fired on the handle element of a drag item.
<a name="line676"></a> * @param {goog.events.BrowserEvent} e The event.
<a name="line677"></a> * @private
<a name="line678"></a> */
<a name="line679"></a>goog.fx.DragListGroup.prototype.handleDragItemHandleMouseover_ = function(e) {
<a name="line680"></a>  goog.dom.classes.add(/** @type {Element} */ (e.currentTarget),
<a name="line681"></a>      this.dragItemHandleHoverClass_);
<a name="line682"></a>};
<a name="line683"></a>
<a name="line684"></a>
<a name="line685"></a>/**
<a name="line686"></a> * Handles a MOUSEOUT event fired on the handle element of a drag item.
<a name="line687"></a> * @param {goog.events.BrowserEvent} e The event.
<a name="line688"></a> * @private
<a name="line689"></a> */
<a name="line690"></a>goog.fx.DragListGroup.prototype.handleDragItemHandleMouseout_ = function(e) {
<a name="line691"></a>  goog.dom.classes.remove(/** @type {Element} */ (e.currentTarget),
<a name="line692"></a>      this.dragItemHandleHoverClass_);
<a name="line693"></a>};
<a name="line694"></a>
<a name="line695"></a>
<a name="line696"></a>/**
<a name="line697"></a> * Gets the drag items currently in the given drag list.
<a name="line698"></a> * Note: Any drag item can potentially be moved to any drag list.
<a name="line699"></a> *
<a name="line700"></a> * @param {Element} dragList The drag list to get drag items from.
<a name="line701"></a> * @return {Array.&lt;Element&gt;} The drag items currently in the given drag list.
<a name="line702"></a> * @private
<a name="line703"></a> */
<a name="line704"></a>goog.fx.DragListGroup.prototype.getItemsInDragList_ = function(dragList) {
<a name="line705"></a>  var dragItems = [];
<a name="line706"></a>  var childNodes = dragList.childNodes;
<a name="line707"></a>  for (var i = 0, n = childNodes.length; i &lt; n; i++) {
<a name="line708"></a>    if (childNodes[i].nodeType == goog.dom.NodeType.ELEMENT) {
<a name="line709"></a>      dragItems.push(childNodes[i]);
<a name="line710"></a>    }
<a name="line711"></a>  }
<a name="line712"></a>  return dragItems;
<a name="line713"></a>};
<a name="line714"></a>
<a name="line715"></a>
<a name="line716"></a>/**
<a name="line717"></a> * Helper for handleDragMove_().
<a name="line718"></a> * Given the position of the center of the dragger element, figures out whether
<a name="line719"></a> * it&#39;s currently hovering over any of the drag lists.
<a name="line720"></a> *
<a name="line721"></a> * @param {goog.math.Coordinate} draggerElCenter The center position of the
<a name="line722"></a> *     dragger element.
<a name="line723"></a> * @return {Element?} If currently hovering over a drag list, returns the drag
<a name="line724"></a> *     list element. Else returns null.
<a name="line725"></a> * @private
<a name="line726"></a> */
<a name="line727"></a>goog.fx.DragListGroup.prototype.getHoverDragList_ = function(draggerElCenter) {
<a name="line728"></a>
<a name="line729"></a>  // If the current drag item was in a list last time we did this, then check
<a name="line730"></a>  // that same list first.
<a name="line731"></a>  var prevHoverList = null;
<a name="line732"></a>  if (this.currDragItem_.style.display != &#39;none&#39;) {
<a name="line733"></a>    prevHoverList = /** @type {Element} */ (this.currDragItem_.parentNode);
<a name="line734"></a>    // Important: We can&#39;t use the cached bounds for this list because the
<a name="line735"></a>    // cached bounds are based on the case where the current drag item is not
<a name="line736"></a>    // in the list. Since the current drag item is known to be in this list, we
<a name="line737"></a>    // must recompute the list&#39;s bounds.
<a name="line738"></a>    var prevHoverListBounds = goog.style.getBounds(prevHoverList);
<a name="line739"></a>    if (this.isInRect_(draggerElCenter, prevHoverListBounds)) {
<a name="line740"></a>      return prevHoverList;
<a name="line741"></a>    }
<a name="line742"></a>  }
<a name="line743"></a>
<a name="line744"></a>  for (var i = 0, n = this.dragLists_.length; i &lt; n; i++) {
<a name="line745"></a>    var dragList = this.dragLists_[i];
<a name="line746"></a>    if (dragList == prevHoverList) {
<a name="line747"></a>      continue;
<a name="line748"></a>    }
<a name="line749"></a>    if (this.isInRect_(draggerElCenter, dragList.dlgBounds_)) {
<a name="line750"></a>      return dragList;
<a name="line751"></a>    }
<a name="line752"></a>  }
<a name="line753"></a>
<a name="line754"></a>  return null;
<a name="line755"></a>};
<a name="line756"></a>
<a name="line757"></a>
<a name="line758"></a>/**
<a name="line759"></a> * Checks whether a coordinate position resides inside a rectangle.
<a name="line760"></a> * @param {goog.math.Coordinate} pos The coordinate position.
<a name="line761"></a> * @param {goog.math.Rect} rect The rectangle.
<a name="line762"></a> * @return {boolean} True if &#39;pos&#39; is within the bounds of &#39;rect&#39;.
<a name="line763"></a> * @private
<a name="line764"></a> */
<a name="line765"></a>goog.fx.DragListGroup.prototype.isInRect_ = function(pos, rect) {
<a name="line766"></a>  return pos.x &gt; rect.left &amp;&amp; pos.x &lt; rect.left + rect.width &amp;&amp;
<a name="line767"></a>         pos.y &gt; rect.top &amp;&amp; pos.y &lt; rect.top + rect.height;
<a name="line768"></a>};
<a name="line769"></a>
<a name="line770"></a>
<a name="line771"></a>/**
<a name="line772"></a> * Helper for handleDragMove_().
<a name="line773"></a> * Given the position of the center of the dragger element, plus the drag list
<a name="line774"></a> * that it&#39;s currently hovering over, figures out the next drag item in the
<a name="line775"></a> * list that follows the current position of the dragger element. (I.e. if
<a name="line776"></a> * the drag action ends right now, it would become the item after the current
<a name="line777"></a> * drag item.)
<a name="line778"></a> *
<a name="line779"></a> * @param {Element?} hoverList The drag list that we&#39;re hovering over.
<a name="line780"></a> * @param {goog.math.Coordinate} draggerElCenter The center position of the
<a name="line781"></a> *     dragger element.
<a name="line782"></a> * @return {Element?} Returns the earliest item in the hover list that belongs
<a name="line783"></a> *     after the current position of the dragger element. If all items in the
<a name="line784"></a> *     list should come before the current drag item, then returns null.
<a name="line785"></a> * @private
<a name="line786"></a> */
<a name="line787"></a>goog.fx.DragListGroup.prototype.getHoverNextItem_ = function(
<a name="line788"></a>    hoverList, draggerElCenter) {
<a name="line789"></a>  if (hoverList == null) {
<a name="line790"></a>    throw Error(&#39;getHoverNextItem_ called with null hoverList.&#39;);
<a name="line791"></a>  }
<a name="line792"></a>
<a name="line793"></a>  // The definition of what it means for the draggerEl to be &quot;before&quot; a given
<a name="line794"></a>  // item in the hover drag list is not always the same. It changes based on
<a name="line795"></a>  // the growth direction of the hover drag list in question.
<a name="line796"></a>  /** @type {number} */
<a name="line797"></a>  var relevantCoord;
<a name="line798"></a>  var getRelevantBoundFn;
<a name="line799"></a>  var isBeforeFn;
<a name="line800"></a>  switch (hoverList.dlgGrowthDirection_) {
<a name="line801"></a>    case goog.fx.DragListDirection.DOWN:
<a name="line802"></a>      // &quot;Before&quot; means draggerElCenter.y is less than item&#39;s bottom y-value.
<a name="line803"></a>      relevantCoord = draggerElCenter.y;
<a name="line804"></a>      getRelevantBoundFn = goog.fx.DragListGroup.getBottomBound_;
<a name="line805"></a>      isBeforeFn = goog.fx.DragListGroup.isLessThan_;
<a name="line806"></a>      break;
<a name="line807"></a>    case goog.fx.DragListDirection.UP:
<a name="line808"></a>      // &quot;Before&quot; means draggerElCenter.y is greater than item&#39;s top y-value.
<a name="line809"></a>      relevantCoord = draggerElCenter.y;
<a name="line810"></a>      getRelevantBoundFn = goog.fx.DragListGroup.getTopBound_;
<a name="line811"></a>      isBeforeFn = goog.fx.DragListGroup.isGreaterThan_;
<a name="line812"></a>      break;
<a name="line813"></a>    case goog.fx.DragListDirection.RIGHT:
<a name="line814"></a>      // &quot;Before&quot; means draggerElCenter.x is less than item&#39;s right x-value.
<a name="line815"></a>      relevantCoord = draggerElCenter.x;
<a name="line816"></a>      getRelevantBoundFn = goog.fx.DragListGroup.getRightBound_;
<a name="line817"></a>      isBeforeFn = goog.fx.DragListGroup.isLessThan_;
<a name="line818"></a>      break;
<a name="line819"></a>    case goog.fx.DragListDirection.LEFT:
<a name="line820"></a>      // &quot;Before&quot; means draggerElCenter.x is greater than item&#39;s left x-value.
<a name="line821"></a>      relevantCoord = draggerElCenter.x;
<a name="line822"></a>      getRelevantBoundFn = goog.fx.DragListGroup.getLeftBound_;
<a name="line823"></a>      isBeforeFn = goog.fx.DragListGroup.isGreaterThan_;
<a name="line824"></a>      break;
<a name="line825"></a>  }
<a name="line826"></a>
<a name="line827"></a>  // This holds the earliest drag item found so far that should come after
<a name="line828"></a>  // this.currDragItem_ in the hover drag list (based on draggerElCenter).
<a name="line829"></a>  var earliestAfterItem = null;
<a name="line830"></a>  // This is the position of the relevant bound for the earliestAfterItem,
<a name="line831"></a>  // where &quot;relevant&quot; is determined by the growth direction of hoverList.
<a name="line832"></a>  var earliestAfterItemRelevantBound;
<a name="line833"></a>
<a name="line834"></a>  var hoverListItems = this.getItemsInDragList_(hoverList);
<a name="line835"></a>  for (var i = 0, n = hoverListItems.length; i &lt; n; i++) {
<a name="line836"></a>    var item = hoverListItems[i];
<a name="line837"></a>    if (item == this.currDragItem_) {
<a name="line838"></a>      continue;
<a name="line839"></a>    }
<a name="line840"></a>
<a name="line841"></a>    var relevantBound = getRelevantBoundFn(item.dlgBounds_);
<a name="line842"></a>    if (isBeforeFn(relevantCoord, relevantBound) &amp;&amp;
<a name="line843"></a>        (earliestAfterItemRelevantBound == undefined ||
<a name="line844"></a>         isBeforeFn(relevantBound, earliestAfterItemRelevantBound))) {
<a name="line845"></a>      earliestAfterItem = item;
<a name="line846"></a>      earliestAfterItemRelevantBound = relevantBound;
<a name="line847"></a>    }
<a name="line848"></a>  }
<a name="line849"></a>
<a name="line850"></a>  return earliestAfterItem;
<a name="line851"></a>};
<a name="line852"></a>
<a name="line853"></a>
<a name="line854"></a>/**
<a name="line855"></a> * Private helper for getHoverNextItem_().
<a name="line856"></a> * Given the bounds of an item, computes the item&#39;s bottom y-value.
<a name="line857"></a> * @param {goog.math.Rect} itemBounds The bounds of the item.
<a name="line858"></a> * @return {number} The item&#39;s bottom y-value.
<a name="line859"></a> * @private
<a name="line860"></a> */
<a name="line861"></a>goog.fx.DragListGroup.getBottomBound_ = function(itemBounds) {
<a name="line862"></a>  return itemBounds.top + itemBounds.height - 1;
<a name="line863"></a>};
<a name="line864"></a>
<a name="line865"></a>/**
<a name="line866"></a> * Private helper for getHoverNextItem_().
<a name="line867"></a> * Given the bounds of an item, computes the item&#39;s top y-value.
<a name="line868"></a> * @param {goog.math.Rect} itemBounds The bounds of the item.
<a name="line869"></a> * @return {number} The item&#39;s top y-value.
<a name="line870"></a> * @private
<a name="line871"></a> */
<a name="line872"></a>goog.fx.DragListGroup.getTopBound_ = function(itemBounds) {
<a name="line873"></a>  return itemBounds.top || 0;
<a name="line874"></a>};
<a name="line875"></a>
<a name="line876"></a>/**
<a name="line877"></a> * Private helper for getHoverNextItem_().
<a name="line878"></a> * Given the bounds of an item, computes the item&#39;s right x-value.
<a name="line879"></a> * @param {goog.math.Rect} itemBounds The bounds of the item.
<a name="line880"></a> * @return {number} The item&#39;s right x-value.
<a name="line881"></a> * @private
<a name="line882"></a> */
<a name="line883"></a>goog.fx.DragListGroup.getRightBound_ = function(itemBounds) {
<a name="line884"></a>  return itemBounds.left + itemBounds.width - 1;
<a name="line885"></a>};
<a name="line886"></a>
<a name="line887"></a>/**
<a name="line888"></a> * Private helper for getHoverNextItem_().
<a name="line889"></a> * Given the bounds of an item, computes the item&#39;s left x-value.
<a name="line890"></a> * @param {goog.math.Rect} itemBounds The bounds of the item.
<a name="line891"></a> * @return {number} The item&#39;s left x-value.
<a name="line892"></a> * @private
<a name="line893"></a> */
<a name="line894"></a>goog.fx.DragListGroup.getLeftBound_ = function(itemBounds) {
<a name="line895"></a>  return itemBounds.left || 0;
<a name="line896"></a>};
<a name="line897"></a>
<a name="line898"></a>/**
<a name="line899"></a> * Private helper for getHoverNextItem_().
<a name="line900"></a> * @param {number} a Number to compare.
<a name="line901"></a> * @param {number} b Number to compare.
<a name="line902"></a> * @return {boolean} Whether a is less than b.
<a name="line903"></a> * @private
<a name="line904"></a> */
<a name="line905"></a>goog.fx.DragListGroup.isLessThan_ = function(a, b) {
<a name="line906"></a>  return a &lt; b;
<a name="line907"></a>};
<a name="line908"></a>
<a name="line909"></a>/**
<a name="line910"></a> * Private helper for getHoverNextItem_().
<a name="line911"></a> * @param {number} a Number to compare.
<a name="line912"></a> * @param {number} b Number to compare.
<a name="line913"></a> * @return {boolean} Whether a is greater than b.
<a name="line914"></a> * @private
<a name="line915"></a> */
<a name="line916"></a>goog.fx.DragListGroup.isGreaterThan_ = function(a, b) {
<a name="line917"></a>  return a &gt; b;
<a name="line918"></a>};
<a name="line919"></a>
<a name="line920"></a>
<a name="line921"></a>/**
<a name="line922"></a> * Inserts the current drag item to the appropriate location in the drag list
<a name="line923"></a> * that we&#39;re hovering over (if the current drag item is not already there).
<a name="line924"></a> *
<a name="line925"></a> * @param {Element} hoverList The drag list we&#39;re hovering over.
<a name="line926"></a> * @param {Element} hoverNextItem The next item in the hover drag list.
<a name="line927"></a> * @private
<a name="line928"></a> */
<a name="line929"></a>goog.fx.DragListGroup.prototype.insertCurrDragItem_ = function(
<a name="line930"></a>    hoverList, hoverNextItem) {
<a name="line931"></a>
<a name="line932"></a>  if (hoverList.dlgIsDocOrderSameAsGrowthDirection_) {
<a name="line933"></a>    if (this.currDragItem_.parentNode != hoverList ||
<a name="line934"></a>        goog.dom.getNextElementSibling(this.currDragItem_) != hoverNextItem) {
<a name="line935"></a>      // The current drag item is not in the correct location, so we move it.
<a name="line936"></a>      // Note: hoverNextItem may be null, but insertBefore() still works.
<a name="line937"></a>      hoverList.insertBefore(this.currDragItem_, hoverNextItem);
<a name="line938"></a>    }
<a name="line939"></a>
<a name="line940"></a>  } else {
<a name="line941"></a>    // Since the doc order of the items is actually the reverse order of the
<a name="line942"></a>    // drag list&#39;s growth direction, we need to insert AFTER the hoverNextItem.
<a name="line943"></a>    if (!hoverNextItem) {
<a name="line944"></a>      // Insert after a non-existent item: actually means insert at beginning.
<a name="line945"></a>      hoverList.insertBefore(this.currDragItem_,
<a name="line946"></a>          goog.dom.getFirstElementChild(hoverList));
<a name="line947"></a>    } else {
<a name="line948"></a>      var actualNextItem = goog.dom.getNextElementSibling(hoverNextItem);
<a name="line949"></a>      // Note: actualNextItem may be null, but insertBefore() still works.
<a name="line950"></a>      hoverList.insertBefore(this.currDragItem_, actualNextItem);
<a name="line951"></a>    }
<a name="line952"></a>  }
<a name="line953"></a>};
<a name="line954"></a>
<a name="line955"></a>
<a name="line956"></a>/**
<a name="line957"></a> * Note: Copied from abstractdragdrop.js. TODO: consolidate.
<a name="line958"></a> * Creates copy of node being dragged.
<a name="line959"></a> *
<a name="line960"></a> * @param {Element} sourceEl Element to copy.
<a name="line961"></a> * @return {Element} The clone of {@code sourceEl}.
<a name="line962"></a> * @private
<a name="line963"></a> */
<a name="line964"></a>goog.fx.DragListGroup.prototype.cloneNode_ = function(sourceEl) {
<a name="line965"></a>  var clonedEl = /** @type {Element} */ (sourceEl.cloneNode(true));
<a name="line966"></a>  switch (sourceEl.tagName.toLowerCase()) {
<a name="line967"></a>    case &#39;tr&#39;:
<a name="line968"></a>      return goog.dom.createDom(
<a name="line969"></a>          &#39;table&#39;, null, goog.dom.createDom(&#39;tbody&#39;, null, clonedEl));
<a name="line970"></a>    case &#39;td&#39;:
<a name="line971"></a>    case &#39;th&#39;:
<a name="line972"></a>      return goog.dom.createDom(
<a name="line973"></a>          &#39;table&#39;, null, goog.dom.createDom(&#39;tbody&#39;, null, goog.dom.createDom(
<a name="line974"></a>          &#39;tr&#39;, null, clonedEl)));
<a name="line975"></a>    default:
<a name="line976"></a>      return clonedEl;
<a name="line977"></a>  }
<a name="line978"></a>};
<a name="line979"></a>
<a name="line980"></a>
<a name="line981"></a>
<a name="line982"></a>/**
<a name="line983"></a> * The event object dispatched by DragListGroup.
<a name="line984"></a> * The fields draggerElCenter, hoverList, and hoverNextItem are only available
<a name="line985"></a> * for the BEFOREDRAGMOVE and DRAGMOVE events.
<a name="line986"></a> *
<a name="line987"></a> * @param {string} type The event type string.
<a name="line988"></a> * @param {goog.fx.DragListGroup} dragListGroup A reference to the associated
<a name="line989"></a> *     DragListGroup object.
<a name="line990"></a> * @param {goog.events.BrowserEvent|goog.fx.DragEvent} event The event fired
<a name="line991"></a> *     by the browser or fired by the dragger.
<a name="line992"></a> * @param {Element} currDragItem The current drag item being moved.
<a name="line993"></a> * @param {Element} draggerEl The clone of the current drag item that&#39;s actually
<a name="line994"></a> *     being dragged around.
<a name="line995"></a> * @param {goog.fx.Dragger} dragger The dragger object.
<a name="line996"></a> * @param {goog.math.Coordinate} opt_draggerElCenter The current center position
<a name="line997"></a> *     of the draggerEl.
<a name="line998"></a> * @param {Element} opt_hoverList The current drag list that&#39;s being hovered
<a name="line999"></a> *     over, or null if the center of draggerEl is outside of any drag lists.
<a name="line1000"></a> *     If not null and the drag action ends right now, then currDragItem will
<a name="line1001"></a> *     end up in this list.
<a name="line1002"></a> * @param {Element} opt_hoverNextItem The current next item in the hoverList
<a name="line1003"></a> *     that the draggerEl is hovering over. (I.e. If the drag action ends
<a name="line1004"></a> *     right now, then this item would become the next item after the new
<a name="line1005"></a> *     location of currDragItem.) May be null if not applicable or if
<a name="line1006"></a> *     currDragItem would be added to the end of hoverList.
<a name="line1007"></a> * @constructor
<a name="line1008"></a> */
<a name="line1009"></a>goog.fx.DragListGroupEvent = function(
<a name="line1010"></a>    type, dragListGroup, event, currDragItem, draggerEl, dragger,
<a name="line1011"></a>    opt_draggerElCenter, opt_hoverList, opt_hoverNextItem) {
<a name="line1012"></a>
<a name="line1013"></a>  /**
<a name="line1014"></a>   * The event type string.
<a name="line1015"></a>   * @type {string}
<a name="line1016"></a>   */
<a name="line1017"></a>  this.type = type;
<a name="line1018"></a>
<a name="line1019"></a>  /**
<a name="line1020"></a>   * A reference to the associated DragListGroup object.
<a name="line1021"></a>   * @type {goog.fx.DragListGroup}
<a name="line1022"></a>   */
<a name="line1023"></a>  this.dragListGroup = dragListGroup;
<a name="line1024"></a>
<a name="line1025"></a>  /**
<a name="line1026"></a>   * The event fired by the browser or fired by the dragger.
<a name="line1027"></a>   * @type {goog.events.BrowserEvent|goog.fx.DragEvent}
<a name="line1028"></a>   */
<a name="line1029"></a>  this.event = event;
<a name="line1030"></a>
<a name="line1031"></a>  /**
<a name="line1032"></a>   * The current drag item being move.
<a name="line1033"></a>   * @type {Element}
<a name="line1034"></a>   */
<a name="line1035"></a>  this.currDragItem = currDragItem;
<a name="line1036"></a>
<a name="line1037"></a>  /**
<a name="line1038"></a>   * The clone of the current drag item that&#39;s actually being dragged around.
<a name="line1039"></a>   * @type {Element}
<a name="line1040"></a>   */
<a name="line1041"></a>  this.draggerEl = draggerEl;
<a name="line1042"></a>
<a name="line1043"></a>  /**
<a name="line1044"></a>   * The dragger object.
<a name="line1045"></a>   * @type {goog.fx.Dragger}
<a name="line1046"></a>   */
<a name="line1047"></a>  this.dragger = dragger;
<a name="line1048"></a>
<a name="line1049"></a>  /**
<a name="line1050"></a>   * The current center position of the draggerEl.
<a name="line1051"></a>   * @type {goog.math.Coordinate|undefined}
<a name="line1052"></a>   */
<a name="line1053"></a>  this.draggerElCenter = opt_draggerElCenter;
<a name="line1054"></a>
<a name="line1055"></a>  /**
<a name="line1056"></a>   * The current drag list that&#39;s being hovered over, or null if the center of
<a name="line1057"></a>   * draggerEl is outside of any drag lists. (I.e. If not null and the drag
<a name="line1058"></a>   * action ends right now, then currDragItem will end up in this list.)
<a name="line1059"></a>   * @type {Element|undefined}
<a name="line1060"></a>   */
<a name="line1061"></a>  this.hoverList = opt_hoverList;
<a name="line1062"></a>
<a name="line1063"></a>  /**
<a name="line1064"></a>   * The current next item in the hoverList that the draggerEl is hovering over.
<a name="line1065"></a>   * (I.e. If the drag action ends right now, then this item would become the
<a name="line1066"></a>   * next item after the new location of currDragItem.) May be null if not
<a name="line1067"></a>   * applicable or if currDragItem would be added to the end of hoverList.
<a name="line1068"></a>   * @type {Element|undefined}
<a name="line1069"></a>   */
<a name="line1070"></a>  this.hoverNextItem = opt_hoverNextItem;
<a name="line1071"></a>};
</pre>


</body>
</html>
